﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Linq;
using Common.Library;


namespace CommonControls.AboutApps
{
    public static class AboutMenu
    {
        public static List<AboutUsProperties> LoadMenuItems()
        {
            List<AboutUsProperties> objList = new List<AboutUsProperties>();
            try
            {
                XDocument xdoc = XDocument.Load(Constants.AboutUsMenuXmlPath);

                var list = from i in xdoc.Descendants("Item") select i;
                foreach (var element in list)
                {
                    AboutUsProperties objItem = new AboutUsProperties();
                    objItem.Id = element.Attribute("Id").Value;

                    if (objItem.Id == "3")
                    {
                        objItem.CountVisible = Visibility.Visible;
                        objItem.Name = element.Attribute("Name").Value;

                        if (AppSettings.RelatedAppCount > 10)
                        {
                            objItem.Count = AppSettings.RelatedAppCount.ToString();
                            if (objItem.Count.Length == 1)
                                objItem.margen = "28,-8,0,0";
                            else
                                objItem.margen = "23,-8,0,0";
                        }
                        else
                        {
                            objItem.margen = "23,-8,0,0";
                            objItem.Count = "10";
                        }
                    }
                    else
                    {
                        objItem.Name = element.Attribute("Name").Value;
                        objItem.CountVisible = Visibility.Collapsed;
                    }

                    if (objItem.Id == "5" && AppSettings.ShowUpgradePage)
                        objList.Add(objItem);
                }
            }
            catch (Exception ex)
            {
                if (AppSettings.AutomaticallyEmailErrors)
                {
                    Exceptions.SaveOrSendExceptions("Exception in LoadMenuItems Method In About.cs file.", ex);
                }
            }
            return objList;
        }
    }
}
